menubutton: dismiss menu/popover when toggling programmatically
authorPaolo Borelli <pborelli@gnome.org>
Wed, 27 Aug 2014 19:36:08 +0000 (21:36 +0200)
committerPaolo Borelli <pborelli@gnome.org>
Thu, 28 Aug 2014 19:16:19 +0000 (21:16 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=735545

gtk/gtkmenubutton.c

index 605937aad3ada9159ff0312d25efe4215e1fc1e1..656392f97df65d9b1036aea3e0538fe8c2175602 100644 (file)
@@ -408,23 +408,28 @@ gtk_menu_button_toggled (GtkToggleButton *button)
 {
   GtkMenuButton *menu_button = GTK_MENU_BUTTON (button);
   GtkMenuButtonPrivate *priv = menu_button->priv;
+  gboolean active;
 
-  if (!gtk_toggle_button_get_active (button))
-    return;
+  active = gtk_toggle_button_get_active (button);
 
   if (priv->menu)
-    {  
-      if (!gtk_widget_get_visible (priv->menu))
+    {
+      if (active)
         {
-          /* we get here only when the menu is activated by a key
-           * press, so that we can select the first menu item
-           */
-          popup_menu (menu_button, NULL);
-          gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
+          if (!gtk_widget_get_visible (priv->menu))
+            {
+              /* we get here only when the menu is activated by a key
+               * press, so that we can select the first menu item
+               */
+              popup_menu (menu_button, NULL);
+              gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
+            }
         }
+      else
+        gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
     }
   else if (priv->popover)
-    gtk_widget_show (priv->popover); 
+    gtk_widget_set_visible (priv->popover, active);
 }
 
 static gboolean